<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>迭代器模式</title>
  </head>
  <body></body>
  <script>
    // 统一遍历接口实现
    function myForEach(arr, callback) {
      for (let i = 0; i < arr.length; i++) {
        callback(i, arr[i]);
      }
    }

    // 外部调用
    myForEach([1, 2, 3, 4, 5, 6], function (index, value) {
      console.log([index, value]);
    });
  </script>
</html>
